package org.jsola.hr.helper;

import org.jsola.common.SafeKit;
import org.jsola.hr.dto.EmpModifyPhoneAddDTO;
import org.jsola.hr.dto.EmpModifyPhoneUpdateDTO;
import org.jsola.hr.entity.EmpModifyPhoneDO;
import org.jsola.hr.query.EmpModifyPhoneQuery;
import org.jsola.hr.service.IEmpModifyPhoneService;
import org.jsola.hr.vo.EmpModifyPhoneVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;

import java.util.List;

import static org.jsola.hr.core.AbstractTest.SITE_ID;



/**
 * 员工修改手机号
 *
 * @author zhr
 */
@Component
public class EmpModifyPhoneTestHelper extends BaseTestHelper {
    
    @Autowired
    private IEmpModifyPhoneService empModifyPhoneService;

    /**
     * 生成add测试数据
     * @return EmpModifyPhoneAddDTO
     */
    public EmpModifyPhoneAddDTO getEmpModifyPhoneAddDTO(){
        EmpModifyPhoneAddDTO empModifyPhoneAddDTO = new EmpModifyPhoneAddDTO();
        empModifyPhoneAddDTO.setEmpId(getRandomValue("varchar",32));
        empModifyPhoneAddDTO.setOldUserId(getRandomValue("varchar",32));
        empModifyPhoneAddDTO.setNewUserId(getRandomValue("varchar",32));
        empModifyPhoneAddDTO.setOldPhone(getRandomValue("varchar",32));
        empModifyPhoneAddDTO.setNewPhone(getRandomValue("varchar",32));
        empModifyPhoneAddDTO.setIsUpdateUserId(SafeKit.getBoolean(getRandomValue("tinyint",1)));
        empModifyPhoneAddDTO.setRemark(getRandomValue("varchar",100));
        return empModifyPhoneAddDTO;
    }


    /**
     * 生成update测试数据
     * @return EmpModifyPhoneUpdateDTO
     */
    public EmpModifyPhoneUpdateDTO getEmpModifyPhoneUpdateDTO(EmpModifyPhoneVO empModifyPhoneVO){
        return empModifyPhoneService.selectDOById(empModifyPhoneVO.getId(), SITE_ID).to(EmpModifyPhoneUpdateDTO.class);
    }

    /**
     * 生成查询数据
     * @return EmpModifyPhoneQuery
     */
    public EmpModifyPhoneQuery getEmpModifyPhoneQuery() {
        EmpModifyPhoneQuery empModifyPhoneQuery = new EmpModifyPhoneQuery();
        List<EmpModifyPhoneDO> empModifyPhoneDOList = empModifyPhoneService.list(new EmpModifyPhoneDO(),SITE_ID);
        if (!CollectionUtils.isEmpty(empModifyPhoneDOList)) {
            EmpModifyPhoneDO empModifyPhoneDO = empModifyPhoneDOList.get(0);
            empModifyPhoneQuery = empModifyPhoneDO.to(EmpModifyPhoneQuery.class);
        }
        return empModifyPhoneQuery;
    }

    /**
     * 保存示例
     * @return EmpModifyPhoneVO
     */
    public EmpModifyPhoneVO saveEmpModifyPhoneExample(){
        EmpModifyPhoneAddDTO addDTO = this.getEmpModifyPhoneAddDTO();
        EmpModifyPhoneVO empModifyPhoneVO = empModifyPhoneService.save(addDTO,buildTokenUser());
        return empModifyPhoneVO;
    }


}

